package com.wasp.collector.service.akka;

import java.util.Comparator;

import com.typesafe.config.Config;
import com.wasp.collector.data.TimeInterval;

import akka.actor.ActorSystem;
import akka.actor.PoisonPill;
import akka.dispatch.Envelope;
import akka.dispatch.PriorityGenerator;
import akka.dispatch.UnboundedPriorityMailbox;

public class CollectPriorityMailbox extends UnboundedPriorityMailbox {
	public CollectPriorityMailbox(Comparator<Envelope> cmp) {
		super(cmp);
		// TODO Auto-generated constructor stub
	}

	// needed for reflective instantiation
	public CollectPriorityMailbox(ActorSystem.Settings settings, Config config) {
		// Create a new PriorityGenerator, lower prio means more important
		super(new PriorityGenerator() {
			@Override
			public int gen(Object message) {
				if (message instanceof TimeInterval) {
					return 0; // 'highpriority messages should be treated
								// first if possible
				} else if (message.equals(PoisonPill.getInstance())) {
					return 3; // PoisonPill when no other left
				} else {
					return 1; // By default they go between high and low
								// prio
				}
			}
		});
	}
}